package com.net.shop.car.manager.api.volley.response.jifen;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.net.shop.car.manager.api.model.JifenGood;
import com.net.shop.car.manager.api.volley.Response;
import com.net.shop.car.manager.utils.Constants;
import com.net.shop.car.manager.utils.LogUtils;
import com.net.shop.car.manager.utils.StringUtils;

public class JifenExchangeListResponse extends Response {
	
	/**
	 * 
	 */
	private int totalPage;
	
	/**
	 * 
	 */
	private List<JifenGood> jifenGoods;

	public JifenExchangeListResponse() {
		super(Constants.JIFEN_EXCHANGE);
	}
	
	@Override
	public String[] getContentTags() {
		// TODO Auto-generated method stub
		return new String[]{"pointype","pagesize"};
	}
	
	@Override
	public void parseContent(String content, int index) {
		if (index == 0) {
			parseJifen(content);
		} else if (index == 1) {
			totalPage = StringUtils.filterIntegerNull(content);
		}
	}
	
	/**
	 * @param content String
	 */
	private void parseJifen(String content) {
		try {
			JSONArray jsonArray = new JSONArray(content);
			jifenGoods = new ArrayList<JifenGood>();
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				JifenGood jifenGood = new JifenGood();
				jifenGood.setGoodName(StringUtils.filterNull(jsonObject.getString("PRODUCT_NAME")));
				jifenGood.setGoodId(StringUtils.filterNull(jsonObject.getString("ID")));
				jifenGood.setGoodLogo(StringUtils.filterNull(jsonObject.getString("PRODUCT_IMAGE")));
				jifenGood.setGoodDes(StringUtils.filterNull(jsonObject.getString("PRODUCT_DESC")));
				jifenGood.setSellerId(StringUtils.filterNull(jsonObject.getString("SELLER_ID")));
				jifenGood.setPointsRequested(StringUtils.filterLongNull(jsonObject.getString("POINTS_REQUIRED")));
				jifenGoods.add(jifenGood);
			}
		} catch (JSONException e) {
			LogUtils.e(e.getMessage());
		}
	}

	/**
	 * @return the totalPage
	 */
	public int getTotalPage() {
		return totalPage;
	}

	/**
	 * @return the jifenGoods
	 */
	public List<JifenGood> getJifenGoods() {
		return jifenGoods;
	}

}
